var o = getApp();

Page({
    data: {
        language: "",
        member_coupon: "",
        goods_id: "",
        coupon: "",
        goods: "",
        goodsid: "",
        shop_logo: "",
        start: "",
        end: ""
    },
    onLoad: function(t) {
        if (t.scene) {
            var a = decodeURIComponent(t.scene);
            if (console.log(a, "ssssssssssssss"), a) {
                var n = [];
                n = a.split(",");
                for (var s = 0; s < n.length; s++) {
                    var e;
                    "vgid" == (e = n[s].split("="))[0] ? this.setData({
                        goods_id: e[1]
                    }) : "mid" == e[0] ? o._setMid(e[1]) : "vcpn" == e[0] && this.setData({
                        member_coupon: e[1]
                    });
                }
            }
        } else t.member_coupon && this.setData({
            member_coupon: t.member_coupon
        }), t.goods_id && this.setData({
            goods_id: t.goods_id
        });
        this.getData();
    },
    getData: function() {
        var t = this, a = o.getNetAddresss("plugin.coupon-qr.api.index.index");
        o._postNetWork({
            url: a,
            showToastIn: !1,
            data: {
                goods_id: t.data.goods_id ? t.data.goods_id : 0,
                member_coupon_id: t.data.member_coupon
            },
            success: function(o) {
                var a = o.data;
                if (1 == a.result) {
                    var n = "", s = "", e = "", d = "";
                    a.data.coupon.start && (n = t.format(a.data.coupon.start)), a.data.coupon.end && (s = t.format(a.data.coupon.end)), 
                    a.data.goods && a.data.goods.id && (e = a.data.goods.id), a.data.shop_logo && (d = a.data.shop_logo), 
                    t.setData({
                        shop_logo: d,
                        goodsid: e,
                        start: n,
                        end: s,
                        coupon: a.data.coupon,
                        goods: a.data.goods
                    }), a.data.coupon.coupon_status && 1 == a.data.coupon.coupon_status && 1 == a.data.goods.status ? wx.showToast({
                        icon: "none",
                        title: "该优惠券已被领取",
                        duration: 1500,
                        success: function() {
                            setTimeout(function() {
                                t.gogoods();
                            }, 1500);
                        }
                    }) : t.data.coupon.link && wx.showToast({
                        icon: "none",
                        title: a.msg,
                        duration: 1500,
                        success: function() {
                            setTimeout(function() {
                                wx.navigateTo({
                                    url: t.data.coupon.link
                                });
                            }, 1500);
                        }
                    });
                } else wx.showToast({
                    icon: "none",
                    title: a.msg,
                    duration: 1500,
                    success: function() {
                        setTimeout(function() {
                            wx.reLaunch({
                                url: "/packageG/index/index"
                            });
                        }, 1500);
                    }
                });
            },
            fail: function(o) {
                console.log(o.msg);
            }
        });
    },
    add0: function(o) {
        return o < 10 ? "0" + o : o;
    },
    format: function(o) {
        var t = new Date(1e3 * o), a = t.getFullYear(), n = t.getMonth() + 1, s = t.getDate();
        return a + "." + this.add0(n) + "." + this.add0(s);
    },
    onReady: function() {
        var o = wx.getStorageSync("langIndex");
        this.setData({
            language: o.en
        });
    },
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    gogoods: function() {
        wx.redirectTo({
            url: "/packageA/detail_v2/detail_v2?id=" + this.data.goodsid
        });
    }
});